package com.xinqi.modules.homework.homework.controller.app;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.modules.homework.homework.dto.req.CourseHomeworkFileUpdateDTO;
import com.xinqi.modules.homework.homework.dto.rsp.CourseHomeworkFileResultDTO;
import com.xinqi.modules.homework.homework.service.CourseHomeworkFileService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 作业学生提交文件APP接口
 *
 * @author: system
 * @date: 2023/03/08
 */
@Tag(name = "App-作业学生提交文件", description = "作业学生提交文件APP接口")
@RestController
@RequestMapping("/app/homework-file")
@RequiredArgsConstructor
public class CourseHomeworkFileAppController {

    private final CourseHomeworkFileService courseHomeworkFileService;

    /**
     * 老师批注学生作业
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @PutMapping("/{id}")
    public R<String> update(@PathVariable("id") Long id, @RequestBody CourseHomeworkFileUpdateDTO dto) {
        dto.setId(id);
        if (courseHomeworkFileService.updateById(dto)) {
            return R.ok(MessageUtils.message("course.homework.note.success"));
        } else {
            return R.ok(MessageUtils.message("course.homework.note.fail"));
        }
    }

    /**
     * 查看学生批注信息
     *
     * @Author dzy
     * @Date 10:10 2023/3/9 0009
     * @Return
     */
    @GetMapping("/{id}")
    public R<CourseHomeworkFileResultDTO> select(@PathVariable("id") Long id) {
        return R.data(courseHomeworkFileService.findById(id));
    }

}
